<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>切换用户</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/res/css/mainstyle.css" />
    <style type="text/css">
    ul
    {
        list-style-type: none;
        margin-left: 5px;
        margin-bottom: 0px;
        margin-right: 0px;
        margin-top: 0px;
    }
    ul li a
    {
        display: block;
        width: 140px;
    }
    ul li a:hover
    {
        background: #36c;
    }
    ul li a:link
    {
        font-size: 12px;
        line-height: 22px;
        text-decoration: none;
        color: #000000;
    }
    ul li a:visited
    {
        font-size: 12px;
        line-height: 22px;
        text-decoration: none;
        color: #000000;
    }
    .divCommon
    {
        margin: 0 0 0 6px;
        padding: 0 0 0 1px;
        border-right: #808080 1px solid;
        border-top: #808080 1px solid;
        border-left: #808080 1px solid;
        border-bottom: #808080 1px solid;
        background: #fff;
        overflow: hidden;
        text-align: left;
        width: 143px;
        height: auto;
        overflow: hidden;
        position: absolute;
    }
    .divCommon ul
    {
        margin-left: 0;
        padding-left: 2px;
        width: 100%;
    }
    .divCommon ul li
    {
        line-height: 20px;
        margin-left: 0;
        padding: 0;
        width: 100%;
        height: 18px;
    }
    .divCommon ul li p
    {
        margin: 0;
        padding: 0;
        font-size: 12px;
        line-height: 22px;
        text-decoration: none;
        color: #000000;
        cursor: pointer;
    }
    .divCommon ul li a
    {
        display: block;
        width: 100%;
    }
    .highlight
    {
        background: #36c;
    }
</style>
    <script src="${pageContext.request.contextPath}/res/js/manCookies.js" type="text/javascript"></script>
    <script type="text/javascript">
        //关闭层
        function closeDIV() {
            parent.window.document.body.removeChild(parent.window.document.getElementById("bgDiv"));
            parent.window.document.body.removeChild(parent.window.document.getElementById("msgDiv"));
        }
        //刷新页面
        function Refresh() {
            var cbBox = document.getElementById("cbSave");
            if (cbBox.checked) {
                setCookies();
            }
            if (document.getElementById("cbClear").checked) {
                DelCookie("loginMessage");
            }            
            document.getElementById("txtMessage").value = '';
            parent.window.document.location.href = 'default.jsp';
        }
        //页面提交
        function onSubmit(object) {
            if (document.getElementById("txtUserId").value == '') {
                document.getElementById("lblTip").innerHTML = '请输入用户名！';
                if (document.getElementById('divDeliveryWay'))
                document.getElementById('divDeliveryWay').style.display = 'none';
                document.getElementById("txtUserId").focus();
                return false;
            }
            if (document.getElementById("txtPassowrd").value == '') {
                document.getElementById("lblTip").innerHTML = '请输入密码！';
                if (document.getElementById('divDeliveryWay'))
                document.getElementById('divDeliveryWay').style.display = 'none';
                document.getElementById("txtPassowrd").focus();
                return false;
            }
            var cbBox = document.getElementById("cbSave");
            if (cbBox.checked) {
                var loginMessage = '';
                if(GetCookie('loginMessage'))
                    loginMessage = GetCookie('loginMessage')
                if (loginMessage.length > 0)
                    loginMessage = loginMessage + document.getElementById("txtUserId").value + ',' + document.getElementById("txtPassowrd").value + '|';
                else
                    loginMessage = document.getElementById("txtUserId").value + ',' + document.getElementById("txtPassowrd").value + '|';
                document.getElementById("txtMessage").value = loginMessage;
            }
            object.submit();
        }
        //文本框获得焦点时
        function onDisCook() {
            document.getElementById('aa').innerHTML = CookToDis();
        }
        //设置Cookies；名称为loginMessage；值为:用户名,密码|
        function setCookies() {
            var loginMessage = CookToStr(document.getElementById("txtMessage").value);
            DelCookie("loginMessage");
            SetCookie("loginMessage", loginMessage, "m", 2);
        }

        //有Cookies字符串，转换成可存储的字符串
        function CookToStr(lm) {
            var arrLm = new Array();
            arrLm = lm.split('|');
            var arrM = new Array();
            var isBool = false;
            lm = '';
            var i = arrLm.length - 5; //最多存储5个用户名密码
            if (i < 0) i = 0;
            j = i;
            var m = i;
            for (var i ; i < arrLm.length; i++) {
                arrM[i] = arrLm[i].split(',');
                if (i > 0) {
                    for (j; j < i; j++) {
                        if (arrM[i][0] == arrM[j][0]) {
                            arrM[j][0] = '';                        
                        }
                    }
                }
            }
            for (m ; m < arrM.length; m++) {
                if (arrM[m][0] != '') {
                    lm = lm + arrM[m][0] + ',' + arrM[m][1] + '|';
                }
            }
            return lm;
        }
        //根据Cookies的内容，显示提示信息
        function CookToDis() {
            var strDis = '';
            var loginMessage = '';
            if (GetCookie('loginMessage'))
                loginMessage = GetCookie('loginMessage');                
            if (loginMessage.length > 0 ) {
                var arrLm = new Array();
                arrLm = loginMessage.split('|');               
                var arrM = new Array();
                if (arrLm.length > 0) {
                    strDis = '<div id="divDeliveryWay" class="divCommon"><ul>';
                    var i = arrLm.length - 5; //最多显示5个用户名密码
                    if (i < 0) i = 0;
                    for (var i; i < arrLm.length; i++) {
                        arrM[i] = arrLm[i].split(',');
                        if (arrM[i][0] != '') {
                            strDis = strDis + '<li><a id="' + arrM[i][1] + '" href="javascript:void(0);" onclick="SelectCommon(this);return false;">' + arrM[i][0] + '</a></li>';
                        }
                    }
                    strDis = strDis + '<li style="text-align:right;"><p onclick="closediv()">关闭&nbsp;</p>&nbsp;</li>';
                    strDis = strDis + '</ul></div>';
                }
            }
            return strDis;
        }
        function SelectCommon(obj) {
            document.getElementById('txtUserId').value = obj.innerHTML;
            document.getElementById('txtPassowrd').value = obj.id;
            if (navigator.userAgent.indexOf("MSIE") > 0) {
                obj.parentElement.parentElement.parentElement.style.display = 'none';
            }
            if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
                obj.parentNode.parentNode.parentNode.style.display = 'none';
            } 
        }
        function closediv() {
            document.getElementById('divDeliveryWay').style.display = 'none';
            if(document.getElementById("txtUserId").value=='')
                document.getElementById("txtUserId").focus();
            else
                document.getElementById("txtPassowrd").focus();            
        }
</script>
</head>
<body>
    <form action="${pageContext.request.contextPath}/ykfk/login.do" method="post" target="_parent">
    <div style="float: none; margin-left: 10px; margin-top: 10px; text-align: center; width: 400px">
        <table style="margin: 0 auto;">
            <tbody>
                <tr>
                    <td colspan="2" class="tdthread">
                        &nbsp;切 换 用 户
                    </td>
                </tr>
                <tr>
                    <td class="tbtitle">&nbsp;用 &nbsp; &nbsp;户 &nbsp; &nbsp;名:</td>
                    <td class="tbright">
                    	&nbsp;<input type="text" id="txtUserId" class="x-form-text" name="loginid" onclick="onDisCook()" style="width:141px;"/><a
                            style="color: Red">*</a> <br /><span id="aa"></span>                       
                    </td>
                </tr>
                <tr>
                    <td class="tbtitle">&nbsp;密&nbsp;&nbsp&nbsp;&nbsp;码:</td>
                    <td class="tbright">
                    	&nbsp;<input type="password" name="userpwd" id="txtPassowrd" class="x-form-text" style="width:141px;"/><a
                            style="color: Red">*</a>
                    </td>
                </tr>                
                <tr>
                    <td align="right">
                        &nbsp;
                    </td>
                    <td class="tbright">
                        <input type="checkbox" id="cbSave"/>记住密码&nbsp;&nbsp;<input type="checkbox" id="cbClear"/>清除记忆
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        &nbsp;
                    </td>
                    <td class="tbright">
                    	 <input type="button" id="submit1" class="anni1" value="确 定" onclick="onSubmit(this.form)" />
                        &nbsp;<span id="lblTip" style="color:Red"></span></td>
                </tr>
            </tbody>
        </table>
    </div>        
    <input id="txtMessage" style="display:none" type="text" />
    </form>
</body>
</html>
<script type="text/javascript">onDisCook();</script>